package com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.ReturnVisitInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.SearchReturnVisitInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.dao.ConsultantDiagnosisDao;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.IConsultantDiagnosisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ConsultantDiagnosisServiceImpl implements IConsultantDiagnosisService {

    @Autowired
    private ConsultantDiagnosisDao dao;

    /**
     * tc 回访记录
     * @param page
     * @param searchInfo
     * @return
     */
    public List<ReturnVisitInfo> selectPageConsultantByQuery(Page<ReturnVisitInfo> page, SearchReturnVisitInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        String tableHead = searchInfo.getAbbreviation();
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())){
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getSreach())) {
            params.put("sreach", searchInfo.getSreach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartDiagnosisTime())) {
            params.put("startDiagnosisTime", searchInfo.getStartDiagnosisTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndDiagnosisTime())) {
            params.put("endDiagnosisTime", searchInfo.getEndDiagnosisTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFollowStatus())) {
            params.put("followStatus", searchInfo.getFollowStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getConsumptionStatus())) {
            params.put("consumptionStatus", searchInfo.getConsumptionStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTcName())) {
            params.put("tcName", searchInfo.getTcName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDealStatus())) {
            if ("已结账".equals(searchInfo.getDealStatus())) {
                params.put("dealStatus", "a.deal_status ='已结账'");
            } else {
                params.put("dealStatus", "a.deal_status !='已结账'");
            }
        }

        params.put("tableName", tableHead + "customer_info");
        return dao.getQueryPage2(page, params);
    }

    public int getQueryPagesCount(Page<ReturnVisitInfo> page, SearchReturnVisitInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        String tableHead = searchInfo.getAbbreviation();
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())){
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getSreach())) {
            params.put("sreach", searchInfo.getSreach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartDiagnosisTime())) {
            params.put("startDiagnosisTime", searchInfo.getStartDiagnosisTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndDiagnosisTime())) {
            params.put("endDiagnosisTime", searchInfo.getEndDiagnosisTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFollowStatus())) {
            params.put("followStatus", searchInfo.getFollowStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getConsumptionStatus())) {
            params.put("consumptionStatus", searchInfo.getConsumptionStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getTcName())) {
            params.put("tcName", searchInfo.getTcName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDealStatus())) {
            if ("已结账".equals(searchInfo.getDealStatus())) {
                params.put("dealStatus", "a.deal_status ='已结账'");
            } else {
                params.put("dealStatus", "a.deal_status !='已结账'");
            }
        }
        params.put("tableName", tableHead + "customer_info");
        return dao.getQueryPagesCount(page, params);
    }

}